package upmc.fr.android.model;

import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;


public class RSSFlow implements Serializable
{
	private static final long serialVersionUID = 1401856095761636808L;
	private String url;
	private List<RSSArticle> articles;
	private String title;
	private String description;

	public RSSFlow()
	{
		articles = new LinkedList<RSSArticle>();
	}
	
	public boolean contains(RSSArticle article)
	{
		return articles.contains(article);
	}
	
	public String getUrl() 
	{
		return url;
	}
	
	public String getTitle() 
	{
		return title;
	}
	
	public String getDescription() 
	{
		return description;
	}
	
	public void setDescription(String description) 
	{		
		this.description = description;
	}
	
	public void setTitle(String title) 
	{
		this.title = title;
	}
	
	public void setUrl(String url) 
	{
		this.url = url;
	}
	
	public void addArticle(RSSArticle article)
	{
		this.articles.add(article);
	}
	
	public void removeArticle(RSSArticle article)
	{
		this.articles.remove(article);
	}
	
	public RSSArticle getArticle(int index)
	{
		return articles.get(index);
	}
	
	public List<RSSArticle> getVisibleArticles()
	{
		List<RSSArticle> result = new LinkedList<RSSArticle>();
		for(RSSArticle article : articles)
		{
			if(!article.isHidden())
				result.add(article);
		}
		return result;
	}

	public List<RSSArticle> getAllArticles()
	{
		return articles;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((url == null) ? 0 : url.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		RSSFlow other = (RSSFlow) obj;
		if (url == null) {
			if (other.url != null)
				return false;
		} else if (!url.equals(other.url))
			return false;
		return true;
	}
	
}
